#include "FindPasswordDlg.h"

#include <core/ImageMgr.h>
#include <core/StyleMgr.h>
#include <widgets/SLineEdit.h>

#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QSpacerItem>
#include <QStylePainter>
#include <QTimer>
#include <QTimerEvent>
#include <QVBoxLayout>
#include <QWidget>
#include <QtNetwork>
#include <map>
#include <regex>

#include "FadeTips.h"
#include "FindPasswordWebReq.h"
#include "FindPwdChangePwdDlg.h"
#include "FindPwdMobileVerifyDlg.h"
#include "FindPwdUserInfoVerifyDlg.h"
#include "uam/UserAccountManager.h"
const UINT nNum = 0x1;
const UINT nChat = 0x2;
const UINT nBoth = 0x3;
const int nMinSize = 8;
const int nMaxSize = 20;

FindPasswordDlg::FindPasswordDlg(QWidget* p /*= nullptr*/) : SPopupWindow(p) {
  setTitle(tr("找回密码"));
  setStep(step_Start_0);

  m_mainLayout = contentLayout();
  m_mainLayout->setSpacing(0);
  m_mainLayout->setContentsMargins(40, 35, 0, 0);

  // step_0: 手机验证
  m_findPwdMobileVerifyDlg = new FindPwdMobileVerifyDlg(this);
  m_mainLayout->addWidget(m_findPwdMobileVerifyDlg);

  //	m_mainLayout->addSpacing(125);
  //当widget1被hide时,中间spacing未消失，支撑widget之间的spacing转为弹簧
  m_spVItem = new QSpacerItem(0, 125);
  m_mainLayout->addSpacerItem(m_spVItem);

  // 二维码以及label
  m_qrCodeAndLabel = new QrAndLabelWidget(this);
  m_qrCodeAndLabel->setFixedSize(336, 100);
  m_mainLayout->addWidget(m_qrCodeAndLabel);

  m_nextStepButton = addBtn(QMessageBox::Ok, tr("下一步"));
  m_cancelButton = addBtn(QMessageBox::Cancel, tr("取消"));

  connect(m_cancelButton, &QPushButton::clicked, this,
          &FindPasswordDlg::onCloseBtn);
  connect(m_nextStepButton, &QPushButton::clicked, this,
          &FindPasswordDlg::onNextStep);
  connect(m_findPwdMobileVerifyDlg->m_getCodeButton, &QPushButton::clicked,
          this, &FindPasswordDlg::onGetCode);
}

void FindPasswordDlg::paintEvent(QPaintEvent* event) {
  SPopupWindow::paintEvent(event);
  QStylePainter painter(this);

  QRect r = rect();
  QFontMetrics fm(font());
  painter.setPen(StyleMgr::instance().color("EditBorderError"));
  if (m_step == step_Start_0) {
    if (!m_mobileMsg.isEmpty()) {
      int phoneMsgX = r.x() + 48;
      int phoneMsgWidth = fm.horizontalAdvance(m_mobileMsg);

      QRect phoneMsgRect;
      phoneMsgRect.setRect(phoneMsgX, r.y() + 138, phoneMsgWidth, r.height());
      painter.drawText(phoneMsgRect, m_mobileMsg, QTextOption(Qt::AlignLeft));
    }
    if (!m_codeMsg.isEmpty()) {
      int codeMsgX = r.x() + 48;
      int codeMsgWidth = fm.horizontalAdvance(m_codeMsg);

      QRect codeMsgRect;
      codeMsgRect.setRect(codeMsgX, r.y() + 200, codeMsgWidth, r.height());
      painter.drawText(codeMsgRect, m_codeMsg, QTextOption(Qt::AlignLeft));
    }
    if (!m_reminderMsg.isEmpty()) {
      int reminderMsgWarnImgX = r.x() + 48;
      int reminderMsgWidth = fm.horizontalAdvance(m_reminderMsg);

      SImage* warnImg =
          ImgMgr::instance().image("auth_warning_yellow_small",
                                   WidgetStatus::kNormal, devicePixelRatioF());
      if (warnImg) {
        painter.drawImage(QPoint(reminderMsgWarnImgX, r.y() + 225), *warnImg);
      }

      int reminderMsgX = r.x() + 48 + 15 + 4;
      QRect reMsgRect;
      reMsgRect.setRect(reminderMsgX, r.y() + 225, reminderMsgWidth,
                        r.height());
      painter.setPen(StyleMgr::instance().color("HighLightWord"));
      painter.drawText(reMsgRect, m_reminderMsg, QTextOption(Qt::AlignLeft));
    }
  } else if (m_step == step_NoPass_1) {
    if (!m_noPassMsg.isEmpty()) {
      int contentX = r.x() + 131;
      int contentWidth = fm.horizontalAdvance(m_noPassMsg);

      QRect contentRect;
      contentRect.setRect(contentX, r.y() + 170, contentWidth, r.height());
      painter.setPen(StyleMgr::instance().color("SupportingWord"));
      painter.drawText(contentRect, m_noPassMsg, QTextOption(Qt::AlignLeft));
    }
  } else if (m_step == step_Info_2) {
    if (!m_userInfoMsg.isEmpty()) {
      int i = 0;
      for (auto edit : m_findPwdUserInfoDlg->m_userInfoEdit) {
        if (edit->text().isEmpty()) {
          break;
        }
        i++;
      }
      int institutionMsgX = r.x() + 142;
      int institutionMsgWidth = fm.horizontalAdvance(m_userInfoMsg);

      QRect institutionMsgRect;
      institutionMsgRect.setRect(institutionMsgX, r.y() + 120 + i * 43,
                                 institutionMsgWidth, r.height());
      painter.drawText(institutionMsgRect, m_userInfoMsg,
                       QTextOption(Qt::AlignLeft));
    }
  } else if (m_step == step_FindPwd_3) {
    if (!m_changePwdMsg.isEmpty()) {
      painter.setPen(StyleMgr::instance().color("EditBorderError"));
      int i = 0;
      for (auto edit : m_findPwdChangePwdDlg->m_changePwdEdit) {
        if (edit->text().isEmpty()) break;
        i++;
      }
      int changePwdMsgX = r.x() + 50;
      int changePwdWidth = fm.horizontalAdvance(m_changePwdMsg);

      QRect changePwdRect;
      if (i == m_findPwdChangePwdDlg->m_changePwdEdit.size()) i = 0;
      changePwdRect.setRect(changePwdMsgX, r.y() + 202 + i * 72, changePwdWidth,
                            r.height());
      painter.drawText(changePwdRect, m_changePwdMsg,
                       QTextOption(Qt::AlignLeft));
    }

    if (!m_accountName.isEmpty()) {
      int accountNameX = r.x() + 130;
      QFont f;
      f.setPixelSize(15);
      painter.setFont(f);

      int accountNameWidth = fm.horizontalAdvance(m_accountName);
      QRect accountNameRect;
      accountNameRect.setRect(accountNameX, r.y() + 65, accountNameWidth + 80,
                              r.height());  // width会受到font大小的影响而改变
      painter.setPen(StyleMgr::instance().color("HighLightWord"));
      painter.drawText(accountNameRect, m_accountName,
                       QTextOption(Qt::AlignLeft));
    }
  }
}

bool FindPasswordDlg::verifyGetMobileMessage() {
  if (m_step != step_Start_0) return false;
  m_mobileNumber = m_findPwdMobileVerifyDlg->m_mobileNumberEdit->text();
  if (m_mobileNumber.isEmpty()) {
    m_mobileMsg = tr("手机号码输入为空");
    return false;
  } else {
    if (verifyMobileNumber(m_mobileNumber) == false) {
      m_mobileMsg = tr("请输入正确手机号");
      return false;
    } else {
      m_mobileMsg = "";
    }
  }
  return true;
}

bool FindPasswordDlg::verifyMobileNumber(QString phoneNumber) {
  std::regex pieces_regex("1[1-9]\\d{9}");
  std::smatch pieces_match;
  std::string phoneNum = phoneNumber.toStdString();
  bool bMatch = std::regex_match(phoneNum, pieces_match, pieces_regex);
  return bMatch;
}

bool FindPasswordDlg::verifyMobileCode() {  // 验证手机验证码
  CFindPasswordMsg tMsg;
  tMsg.m_nReqID = WEB_GET_VERIFICATION_MOBILE_STATE;
  if (!m_mobileNumber.isEmpty()) {
    tMsg.m_strMobile = m_mobileNumber;
    int nACountState = -1;
    std::map<QString, CFindPasswordMsg>::const_iterator itrFind =
        m_mapState.find(tMsg.m_strMobile);
    if (itrFind != m_mapState.end() && itrFind->second.m_nMobileState >= 0) {
      nACountState = tMsg.m_nMobileState = itrFind->second.m_nMobileState;
      tMsg.m_strAccount = itrFind->second.m_strAccount;
      tMsg.m_strMobile = itrFind->second.m_strMobile;
      tMsg.m_strUserID = itrFind->second.m_strUserID;
      log_info("find password find state : %d!", nACountState);
    } else {
      tMsg.m_strSeverAdress =
          SSUserAccountManager::instance().GetWebOption().LoadURL(
              "WEB_FINDPASSWORD");
      m_webReq.postMessageFunc(tMsg);
      return 0;
    }
    return getVerifyConfirm(nACountState, tMsg);
  } else {
    log_info("the mobileNumber is Null!");
  }
  return false;
}

void FindPasswordDlg::beginMessageTimer() {
  m_nMessageTime = 60;  // 验证码计时默认为60秒
  if (m_timeCountdown == nullptr) {
    m_timeCountdown = new QTimer(this);
    m_timeCountdown->start(1000);
  } else {
    m_timeCountdown->start();
  }
  connect(m_timeCountdown, &QTimer::timeout, this,
          &FindPasswordDlg::onCountDown);
}

void FindPasswordDlg::enableButton(QPushButton* btn, bool enable, QString txt) {
  if (!txt.isEmpty()) btn->setText(txt);
  btn->setDisabled(enable);  // 按钮假死状态
}

void FindPasswordDlg::setVerifyCodeMsgReminder(bool success) {
  if (success)
    m_reminderMsg =
        QString(tr("验证码已发送到您的手机，15分钟内输入有效，请勿泄漏\r\n若收"
                   "不到验证码，请联系客服"));
  else
    m_reminderMsg = QString(tr("验证码发送失败,请重试!"));
}

void FindPasswordDlg::reEnableTimerButton() {
  if (m_nMessageTime >= 1) {
    if (m_timeCountdown->isActive()) m_timeCountdown->stop();
    enableButton(m_findPwdMobileVerifyDlg->m_getCodeButton, false,
                 tr("重新获取"));
  }
}

void FindPasswordDlg::setCodeMsgInfo() {
  CFindPasswordMsg tMsg;
  beginMessageTimer();
  tMsg.m_nReqID = WEB_GET_VERIFICATION_CODE;
  QString phoneNum = m_findPwdMobileVerifyDlg->m_mobileNumberEdit->text();
  if (phoneNum != "") {
    tMsg.m_strMobile = phoneNum;
    tMsg.m_strSeverAdress =
        SSUserAccountManager::instance().GetWebOption().LoadURL(
            "WEB_FINDPASSWORD");
    m_webReq.postMessageFunc(tMsg);
  } else {
    log_info("find password can't send message info !");
  }
}

int FindPasswordDlg::getVerifyConfirm(int nACountState,
                                      CFindPasswordMsg& pMsg) {
  if (nACountState >= 0) {
    if (nACountState == 2) {  // 无匹配账户或者有多个账号
      // 隐藏父窗口相关控件
      hideFindPwdWidget(m_step, nACountState);
      m_noPassMsg = QString(tr("没有匹配您手机的账户，请联系运营人员"));
      update();
      return false;
    }

    pMsg.m_nReqID = WEB_GET_VERIFICATION_CONFIRM;
    QString code = m_findPwdMobileVerifyDlg->m_verifyCode->text();
    if (!code.isEmpty()) {
      pMsg.m_strVerification = code;
      pMsg.m_strSeverAdress =
          SSUserAccountManager::instance().GetWebOption().LoadURL(
              "WEB_FINDPASSWORD");
      m_webReq.postMessageFunc(pMsg);
      return true;
    } else {
      log_info("find password 验证失败,请重新输入!");
      showErrorMsg(QString(tr("验证失败,请重新输入")));
    }
  } else {
    log_info("find password 无法获取到用户信息,请重试!");
    showErrorMsg(QString(tr("无法获取到用户信息,请重试")));
  }
  return false;
}

void FindPasswordDlg::setVerifyCodeErrorTxt() {
  m_codeMsg = QString(tr("请输入正确验证码"));
  update();
}

bool FindPasswordDlg::verifyGetCodeMessage() {
  if (m_step != step_Start_0) return false;
  m_codeNumber = m_findPwdMobileVerifyDlg->m_verifyCode->text();
  if (m_codeNumber.isEmpty()) {
    m_codeMsg = tr("验证码输入为空");
    return false;
  } else {
    m_codeMsg = "";
  }
  return true;
}

bool FindPasswordDlg::verifyUserInfo() {
  if (m_step != step_Info_2) return false;
  for (auto edit : m_findPwdUserInfoDlg->m_userInfoEdit) {
    if (edit->text().isEmpty()) {
      m_userInfoMsg = tr("尚未填写");
      break;
    } else {
      m_userInfoMsg = "";
    }
  }
  return m_userInfoMsg == "" ? true : false;
}

bool FindPasswordDlg::verifyChangePwd() {
  QString newPwd = "", verifyNewPwd = "";

  if (m_findPwdChangePwdDlg == nullptr) return false;

  if (m_findPwdChangePwdDlg->m_changePwdEdit.size() != 0) {
    int i = 0;
    for (auto edit : m_findPwdChangePwdDlg->m_changePwdEdit) {
      if (edit->text().isEmpty()) {
        i == 0 ? m_changePwdMsg = QString(tr("密码不能为空"))
               : m_changePwdMsg = QString(tr("请再次输入新密码"));
        return false;
      }
      i == 0 ? newPwd = edit->text() : verifyNewPwd = edit->text();
      i++;
    }
  }
  int nLen = newPwd.length();
  if (newPwd != verifyNewPwd && newPwd != "") {
    m_changePwdMsg = QString(tr("两次输入不一致"));
    return false;
  } else {
    if (nLen < nMinSize || nLen > nMaxSize) {
      m_changePwdMsg = QString(tr("密码必须是8-20位数字、英文字母组合"));
      return false;
    }
  }

  UINT nCheck = 0;
  int nIndex = 0;
  QByteArray byte = newPwd.toUtf8();
  for (int i = 0; i < nLen; i++) {
    int pwd = int(byte.at(i));
    if (pwd >= 48 && pwd <= 57)  // 0-9
    {
      nCheck |= nNum;
      continue;
    } else if (pwd >= 65 && pwd <= 90)  // A-Z
    {
      nCheck |= nNum;
      continue;
    } else if (pwd >= 97 && pwd <= 122)  // a-z
    {
      nCheck |= nChat;
      continue;
    } else {
      nCheck = 0;
      break;
    }
  }
  if (nCheck != nBoth) {
    m_changePwdMsg = QString(tr("密码必须是8-20位数字、英文字母组合"));
    return false;
  } else {
    m_changePwdMsg = "";
  }
  return true;
}

void FindPasswordDlg::onCloseBtn() { close(); }

void FindPasswordDlg::onGetCode() {
  if (verifyGetMobileMessage()) {
    setCodeMsgInfo();
    connect(&m_webReq, &CFindPasswordWebReq::SendGetMsgComplete, this,
            &FindPasswordDlg::onWebReqMsg, Qt::UniqueConnection);
  }
  update();
}

void FindPasswordDlg::onNextStep() {
  clearReminderMessage();  // 清除消息提示
  switch (m_step) {
    case step_Start_0: {
      if (verifyGetMobileMessage() && verifyGetCodeMessage()) {
        verifyMobileCode();
        connect(&m_webReq, &CFindPasswordWebReq::SendGetMsgComplete, this,
                &FindPasswordDlg::onWebReqMsg, Qt::UniqueConnection);
      }
      update();
      break;
    }
    case step_Info_2: {
      // 验证过的手机号，填写个人信息
      if (verifyUserInfo()) {
        submitUserInfo();
        connect(&m_webReq, &CFindPasswordWebReq::SendPostMsgComplete, this,
                &FindPasswordDlg::onWebReqMsg, Qt::UniqueConnection);
      }
      update();
      break;
    }
    case step_FindPwd_3: {
      if (verifyChangePwd()) {
        submitChangePassword();
        connect(&m_webReq, &CFindPasswordWebReq::SendPutMsgComplete, this,
                &FindPasswordDlg::onWebReqMsg, Qt::UniqueConnection);
      }
      update();
      break;
    }
    default:
      break;
  }
}

void FindPasswordDlg::onCountDown() {
  if (m_nMessageTime <= 1) {
    m_timeCountdown->stop();
    reEnableTimerButton();
  } else {
    m_nMessageTime--;
    QString txt;
    txt = QString(tr("重新获取(%1s)")).arg(QString::number(m_nMessageTime));
    enableButton(m_findPwdMobileVerifyDlg->m_getCodeButton, true, txt);
  }
}

void FindPasswordDlg::onWebReqMsg() {
  qDebug() << "!!";
  if (!m_webReq.pMsg) {
    log_info("find password recv null!");
    return;
  }
  int nReq = m_webReq.pMsg->m_nReqID;
  int nRespon = m_webReq.pMsg->m_nResponse;
  switch (nReq) {
    case WEB_GET_VERIFICATION_CODE: {
      setVerifyCodeMsgReminder(nRespon >= 0);
      if (nRespon < 0) {
        reEnableTimerButton();
      }
      update();
      break;
    }
    case WEB_GET_VERIFICATION_CONFIRM: {
      if (nRespon >= 0) {
        m_webReq.pMsg->m_bVerification = true;
        if (nRespon == 0) {  // 已验证过的手机
          hideFindPwdWidget(m_step, nRespon);
          if (m_findPwdChangePwdDlg == nullptr) {
            m_findPwdChangePwdDlg = new FindPwdChangePwdDlg(this);
            m_findPwdChangePwdDlg->setFixedSize(385, 210);
          }
          m_nextStepButton = changeBtnName(QMessageBox::Ok, "提交");
          setStep(step_FindPwd_3);
          setAccountName();
          m_mainLayout->addWidget(m_findPwdChangePwdDlg);
          update();
        } else if (nRespon == 1) {             // 有账户但未验证
          hideFindPwdWidget(m_step, nRespon);  // 隐藏父窗口控件
          if (m_findPwdUserInfoDlg == nullptr) {
            m_findPwdUserInfoDlg = new FindPwdUserInfoVerifyDlg(this);
            m_findPwdUserInfoDlg->setFixedSize(385, 290);
          }
          setStep(step_Info_2);
          m_mainLayout->addWidget(m_findPwdUserInfoDlg);
          update();
        } else if (nRespon == 2) {  // 无匹配账户或者有多个账号
          hideFindPwdWidget(m_step, nRespon);  // 隐藏父窗口控件
          m_noPassMsg = QString(tr("没有匹配您手机的账户，请联系运营人员"));
          update();
        } else {
          showErrorMsg(QString(tr("未知账户,请重新输入")));
        }
      } else {
        setVerifyCodeErrorTxt();
      }
      break;
    }
    case WEB_GET_VERIFICATION_MOBILE_STATE: {
      if (nRespon >= 0) {
        CFindPasswordMsg msgMobileVerify;
        msgMobileVerify.m_nMobileState = nRespon;
        msgMobileVerify.m_strAccount = m_webReq.pMsg->m_strAccount;
        msgMobileVerify.m_strMobile = m_webReq.pMsg->m_strMobile;
        msgMobileVerify.m_strUserID = m_webReq.pMsg->m_strUserID;
        m_mapState[m_webReq.pMsg->m_strMobile] = msgMobileVerify;
      }
      getVerifyConfirm(nRespon, *m_webReq.pMsg);
      break;
    }
    case WEB_GET_SET_PASSWORD: {
      if (nRespon >= 0) {
        hideFindPwdWidget(m_step, -1);
        if (m_findPwdSuccessOverDlg == nullptr) {
          m_findPwdSuccessOverDlg = new FindPwdSuccessOverDlg(this);
          m_findPwdSuccessOverDlg->setFixedSize(385, 305);
        }
        m_mainLayout->addWidget(m_findPwdSuccessOverDlg);
        connect(m_findPwdSuccessOverDlg->m_reLogin, &QPushButton::clicked, this,
                &FindPasswordDlg::onReLogin);
        update();
      } else {
        showErrorMsg(tr("设置失败, 请重试"));
      }
      update();
      break;
    }
    case WEB_GET_SUBMIT_INFO: {
      if (nRespon >= 0) {
        hideFindPwdWidget(m_step, -1);
        if (m_findPwdChangePwdDlg == nullptr) {
          m_findPwdChangePwdDlg = new FindPwdChangePwdDlg(this);
          m_findPwdChangePwdDlg->setFixedSize(385, 210);
        }
        m_nextStepButton = changeBtnName(QMessageBox::Ok, "提交");
        setAccountName();
        m_mainLayout->addWidget(m_findPwdChangePwdDlg);
        update();
      } else {
        showErrorMsg(tr("提交失败,请重试"));
      }
      break;
    }
    default:
      break;
  }
}

void FindPasswordDlg::onReLogin() {
  close();
  emit clearStartPwd();
}

void FindPasswordDlg::showErrorMsg(const QString& err) {
  if (!m_errTips) {
    m_errTips = new FadeTips(this);
    m_errTips->setMargin(32, 16);
  }
  m_errTips->hide();
  m_errTips->setMessage(err);
  m_errTips->show();
}

void FindPasswordDlg::hideFindPwdWidget(em_FindPasswordStep m_step,
                                        int nRespon) {
  m_findPwdMobileVerifyDlg->hide();
  if (m_step == step_Info_2) {
    if (m_findPwdUserInfoDlg == nullptr) return;
    m_findPwdUserInfoDlg->hide();
    m_nextStepButton->show();
    m_spVItem->changeSize(0, 0);
    setStep(step_FindPwd_3);
  } else if (m_step == step_FindPwd_3) {
    if (m_findPwdChangePwdDlg == nullptr) return;
    m_findPwdChangePwdDlg->hide();
    m_nextStepButton->hide();
    m_cancelButton->hide();
    m_spVItem->changeSize(0, 0);
    setStep(step_Over_4);
  } else if (m_step == step_Start_0) {
    // nRespon = 0 : 有账户 && 已验证个人信息 ->直接修改密码
    // nRespon = 1 : 有账户 && 未验证个人信息 ->验证个人信息
    // nRespon = 2 : 无账户					  ->无匹配账号
    // || 多个账号
    if (nRespon == 0 || nRespon == 1) {
      m_qrCodeAndLabel->hide();
      m_nextStepButton->show();
      m_spVItem->changeSize(0, 0);
    } else if (nRespon == 2) {
      m_spVItem->changeSize(0, 262);
      m_nextStepButton->hide();
      setStep(step_NoPass_1);
    }
  }
}

void FindPasswordDlg::setStep(em_FindPasswordStep step) { m_step = step; }

void FindPasswordDlg::clearReminderMessage() {
  m_mobileMsg.clear();
  m_codeMsg.clear();
  m_reminderMsg.clear();
  m_noPassMsg.clear();
  m_userInfoMsg.clear();
  m_changePwdMsg.clear();
}

void FindPasswordDlg::submitUserInfo() {
  CFindPasswordMsg msg;
  msg.m_nReqID = WEB_GET_SUBMIT_INFO;
  if (loadUserInfoMsg(msg)) {
    msg.m_strSeverAdress =
        SSUserAccountManager::instance().GetWebOption().LoadURL(
            "WEB_FINDPASSWORD");
    m_webReq.postMessageFunc(msg);
  } else {
    log_info("find password sub mit load failed!");
  }
}

bool FindPasswordDlg::loadUserInfoMsg(CFindPasswordMsg& pMsg) {
  int i = 0;
  for (auto edit : m_findPwdUserInfoDlg->m_userInfoEdit) {
    if (edit->text().isEmpty())
      return false;
    else {
      switch (i) {
        case 0:
          pMsg.m_strInititute = edit->text();
        case 1:
          pMsg.m_strDepartment = edit->text();
        case 2:
          pMsg.m_strPosition = edit->text();
        default:
          break;
      }
    }
    i++;
  }
  pMsg.m_strTel = m_findPwdUserInfoDlg->m_telEdit->text();
  pMsg.m_strQQ = m_findPwdUserInfoDlg->m_qqEdit->text();
  pMsg.m_strBussiness = "";
  std::set<int> selects;
  for (int i = 0; i <= 7; i++) {
    bool checked = m_findPwdUserInfoDlg->m_typeSector->getCheck(i);
    if (checked) {
      selects.insert(i);
    }
  }
  QString szSelect = "";
  for (auto it : selects) {
    QString szData = m_findPwdUserInfoDlg->m_typeSector->getDataText(it);
    if (szData.length() <= 0) continue;
    if (szSelect.length() > 0) szSelect += ("|");
    szSelect += szData;
  }
  pMsg.m_strBussiness = szSelect;
  pMsg.m_strUserID = m_webReq.pMsg->m_strUserID;
  return true;
}

bool FindPasswordDlg::loadChangePwdMsg(CFindPasswordMsg& pMsg) {
  if (m_step != step_FindPwd_3) return false;
  if (m_findPwdChangePwdDlg->m_changePwdEdit.size() != 0) {
    pMsg.m_strPassWord = m_findPwdChangePwdDlg->m_changePwdEdit.at(0)->text();
  } else {
    return false;
  }
  pMsg.m_strUserID = m_webReq.pMsg->m_strUserID;
  return true;
}

void FindPasswordDlg::setAccountName() {
  if (m_step == step_FindPwd_3 && m_mobileNumber != "") {
    m_accountName += "  " + m_mapState[m_mobileNumber].m_strAccount;
  }
}

void FindPasswordDlg::submitChangePassword() {
  CFindPasswordMsg msg;
  msg.m_nReqID = WEB_GET_SET_PASSWORD;

  if (loadChangePwdMsg(msg)) {
    msg.m_strSeverAdress =
        SSUserAccountManager::instance().GetWebOption().LoadURL(
            "WEB_FINDPASSWORD");
    m_webReq.postMessageFunc(msg);
  } else {
    log_info("find password change passwd load failed!");
  }
}
